# Maintainer: Felix Yan <felixonmars@archlinux.org>

pkgname=ruby-build-files
pkgver=1.8.1
pkgrel=1
pkgdesc='Abstractions for handling and mapping paths'
arch=(any)
url='https://github.com/ioquatix/build-files'
license=(MIT)
depends=(ruby)
checkdepends=(ruby-covered ruby-rspec)
options=(!emptydirs)
source=(https://github.com/ioquatix/build-files/archive/v$pkgver/$pkgname-$pkgver.tar.gz)
sha256sums=('9ed539ab74e316e44d61c9c0b13c6c299e8dfd905e9ef89551446120146f0d62')

prepare() {
  cd build-files-$pkgver
  sed -e 's|~>|>=|' -e '/signing_key/d' -i build-files.gemspec
  echo "gemspec" > gems.rb
}

build() {
  local _gemdir="$(gem env gemdir)"
  cd build-files-$pkgver
  gem build build-files.gemspec
  gem install \
    --local \
    --verbose \
    --ignore-dependencies \
    --no-user-install \
    --install-dir "tmp_install/$_gemdir" \
    --bindir "tmp_install/usr/bin" \
    build-files-$pkgver.gem
  find "tmp_install/$_gemdir/gems/" \
    -type f \
    \( \
        -iname "*.o" -o \
        -iname "*.c" -o \
        -iname "*.so" -o \
        -iname "*.time" -o \
        -iname "gem.build_complete" -o \
        -iname "Makefile" \
    \) \
    -delete
  rm -r tmp_install/$_gemdir/cache
}

check() {
  local _gemdir="$(gem env gemdir)"
  cd build-files-$pkgver
  GEM_HOME="tmp_install/$_gemdir" rspec
}

package() {
  cd build-files-$pkgver
  cp -a tmp_install/* "$pkgdir"/
}
